package com.tao.dao;

import com.tao.entity.User;

public class UserDao extends BaseDao{
    public User dologin(String name,String pass){
        User u=null;
        try {
            super.connect();
            String sql="select * from user where name=? and pass=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1, name);
            pstmt.setString(2,pass);
            rs=pstmt.executeQuery();
            while(rs.next()){
                u=new User();
                u.setId(rs.getInt(1));
                u.setName(rs.getString(2));
                u.setPass(rs.getString(3));
                u.setAge(rs.getInt(4));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            super.closeAll();
        }
        return u;
    }
    public int insert(User u){
        int row=0;
        try {
            super.connect();
//            String sql="insert into user(name,pass,age) values(?,?,?)";
//            String sql="insert into user1(name,pass) values(?,?)";
            String sql="insert into qfnu_table(username,password) values(?,?)";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1, u.getName());
            pstmt.setString(2,u.getPass());
//            pstmt.setInt(3, u.getAge());
            row=pstmt.executeUpdate();
            System.out.println("插入成功");
        } catch (Exception e) {
            System.out.println("插入失败");
            e.printStackTrace();
        }finally{
            super.closeAll();
        }
        return row;
    }
}

